<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
                //方法1.
                var arr = [1, 2, 3, 3, 4, 5, 1, 8, 1, 6, 1, 10, 14, 12, 13, 12];
                function unique1(arr) {
                    var newArr = []; //新建一个数组
                    for(var i = 0;i<arr.length;i++) {
                        if(newArr.indexOf(arr[i]) == -1) { //若新数组中未包含该项则将其存入新数组
                            newArr.push(arr[i]);
                        }
                    }
                        return newArr;
                }
                console.log(unique1(arr));
                //方法2.
                Array.prototype.unique2 = function(){
                    this.sort(); //先排序
                    var res = [this[0]];
                    for(var i = 1; i < this.length; i++){
                        if(this[i] !== res[res.length - 1]){
                            res.push(this[i]);
                        }
                    }
                    return res;
                }
                var arr = [1,'a','a','b','d','e','e',1,0]
                alert(arr.unique2());
</script>
</body>
</html>